#include <stdio.h>
#include <stdlib.h>

int arr[5000005];

void Swap(int *a, int *b)
{
    int tmp = *a;
    *a = *b;
    *b = tmp;
}

inline int read()
{
    int x = 0, f = 1;
    char ch = getchar();
    while(ch < '0' || ch > '9')
    {
        if (ch == '-')  f = -1;
        ch = getchar();
    }
    while(ch >= '0' && ch <= '9')
    {
        x = (x<<1) + (x<<3) + (ch^48);
        ch = getchar();
    }
    return x * f;
}

void AdjustDown(int *a, int n, int parent)
{
    // 简化运算：假设左孩子就是最小的
    int child = parent * 2 + 1;
    while (child < n) // 临界条件：child 在数组的范围内
        // 为什么是小于号：n 是 size，child 是下标，所以用小于
        // 没有左孩子就一定没有右孩子
    {
        // 选出左右孩子中小/大的那个
        if (child + 1 < n && a[child + 1] > a[child]) // 判断右孩子存在
        {
            child++;// 此时 child 就是小的那个孩子
        }
        if (a[parent] < a[child])
        {
            Swap(&a[parent], &a[child]);
            parent = child;
            child = parent * 2 + 1;
        }
        else
        {
            break;
        }
    }
}

int cmp(const void *e1, const void *e2)
{
    return *(int *)e1 - *(int *)e2;
}

void PrintTopK(int *a, int n, int k)
{
    int *kminHeap = (int *)malloc(sizeof(int) * k);
    if (kminHeap == NULL)
    {
        perror("malloc error");
        return;
    }

    for (int i = 0; i < k; i++)
    {
        kminHeap[i] = a[i];
    }

    for (int i = (k - 2) / 2; i >= 0; i--)
    {
        AdjustDown(kminHeap, k, i);
    }

    for (int i = k; i < n; i++)
    {
        if (a[i] < kminHeap[0])
        {
            kminHeap[0] = a[i];
            AdjustDown(kminHeap, k, 0);
        }
    }

    qsort(kminHeap, k, 4, cmp);
    printf("%d\n", kminHeap[k - 1]);
}

int main()
{
    int t;
    scanf("%d", &t);

    while (t--)
    {
        int n, k;
        scanf("%d %d", &n, &k);
        for (int i = 0; i < n; i++)
        {
            scanf("%d", arr + i);
        }

        PrintTopK(arr, n, k);
    }

    return 0;
}
